<!--策略消息-->
<template>
  <div class="bg">
    
    <list class="list" v-if="notices">
      <refresh class="refresh" @refresh="loadmore" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <cell v-for="(item, index) in notices" v-bind:key="index">

        <div class="notice" :style="{marginTop:index == 0 ? '10px':'0'}">

          <div class="notice-row1">
            <text class="time">{{item.createTime}}</text>
            <text class="content">{{item.content}}</text>
          </div>
        </div>
        <div class="genduo-bg" v-if="hasMore && index == notices.length-1">
          <text class="time">{{'没有更多数据'}}</text>
        </div>
      </cell>
    </list>
  </div>
</template>

<script>

import navigator from "@/_js/navigator";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");


var pageNo =1;
var stId = '';

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('策略消息'));

//策略消息 通知列表
export default {
  
  data() {
    return {
      T:T,
      notices: undefined,
      isRefresh:false, //显示刷新
      hasMore: false,
    };
  },

  mounted() {
    stId = navigator.getParam('stId');
    this.getData(data => {
      this.notices = data;
    });
  },

  methods: {
    
    loadmore() {
      
      this.getData(data => {
        this.notices.push(...data);
      });
    },

    getData(callback) {
      

      if (this.isRefresh) return;
      this.isRefresh = true;

      weexHttp.postX("strategyV2/queryStrategyMessageList",{executeId:stId,pageNo:pageNo},true,(data)=>{
        // modal.toast(data);
        this.isRefresh = false;
        if(data.status == 200){
          var list = data.data;
          for(var i = 0;i < list.length;i++){
            var item = list[i];
            item.createTime = parseTime(item.createTime);
            item.type = 'notice';
          }
          if(list.length > 0){
            pageNo++;
          } 
          this.hasMore = list.length < 20;
          callback(list);
        }else{
          //TODO 提示请求错误
        }
        
      });
    }
  }
}


function parseTime(timestamp){
  var time = new Date(Number(timestamp));
  var month = time.getMonth()+1
  month = month < 10 ? "0"+month : month;

  var day = time.getDate();
  day = day < 10 ? "0"+day : day;

  var hour = time.getHours();
  hour = hour < 10 ? "0"+hour : hour;

  var minute = time.getMinutes();
  minute = minute < 10 ? "0"+minute : minute;

  return month+"/"+day+" "+hour+":"+minute;
}

function ellipsis(val, max) {
  var str = new String(val);
  var bytesCount = 0;
  var end = 0;
  for (var i = 0, n = str.length; i < n; i++) {
    var c = str.charCodeAt(i);
    var cc = 0;
    if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
      cc = 1;
    } else {
      cc = 2;
    }
    bytesCount += cc;
    if (bytesCount > max) {
      end = i;
      break;
    }
  }
  end -= 3;
  return val.substring(0, end + 1) + "...";
}
</script>

<style scoped>
.bg {
  width: 750px;
  background-color: #0B1330;
}
.list {
  width: 750px;
}

.notice {
  width: 750px;
  padding: 30px 28px;
  background-color: #121D39;

  margin-bottom: 5px;

  flex-direction: column;
  justify-content: space-between;
}
/* .notice:active{
  background-color: #32373c;
} */
.notice-row1 {
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
}
.time {
  color: #ffffff;
  font-size: 26px;
}
.content {
  width: 694px;
  display: block;
  font-size: 28px;
  color: #ffffff;
  margin-top:15px;
  /* word-break:break-all; */
}
.genduo-bg {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 750px;
  height: 100px;
}
.refresh {
  width: 750;
  flex-direction: row;
  justify-content: center;
}
</style>